package behaviorPattern.observer.jdk9;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 * @author : Alex Hu
 * date : 2020/3/22 上午11:23
 * description :
 */

public class BeanObserver {
    private boolean property;
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
            this);

    public void setProperty(boolean newValue) {
        boolean oldValue = property;
        property = newValue;
        changeSupport.firePropertyChange("property", oldValue, newValue);
    }

    public void addPropertyChangeListener(PropertyChangeListener l) {
        changeSupport.addPropertyChangeListener(l);
    }

    public void removePropertyChangeListener(PropertyChangeListener l) {
        changeSupport.removePropertyChangeListener(l);
    }
}
